﻿using System;
using Basic4Net.BusinessRules;
using Basic4Net.Entities;
using Basic4Net.OAWeb.Base;

namespace Basic4Net.OAWeb.Module_Accounting
{
    public partial class Calculating : BasePage
    {
        private static Amount _amount;
        protected static Amount HAmount
        {
            get { return _amount ?? (_amount = new Amount()); }
        }

        private t_Amount _a;
// ReSharper disable InconsistentNaming
        protected void Page_Load(object sender, EventArgs e)
// ReSharper restore InconsistentNaming
        {
            _a = HAmount.GetActiveAmount(SchoolMark);

            if (_a != null)
            {
                hidHaveMonth.Value = "1";
                if (_a.FYear.HasValue && _a.FMonth.HasValue && HAmount.HaveAccountData(_a.FYear.Value, _a.FMonth.Value, SchoolMark))
                {
                    labMsg0.Text = String.Format("重新核算{0}年{1}月的绩效工资:", _a.FYear, _a.FMonth);
                    hidHaveData.Value = "1";
                }
                else
                {
                    labMsg0.Text = String.Format("{0}年{1}月的绩效工资还没有进行汇总核算, 进行相关的录入工作后, 请点击:", _a.FYear, _a.FMonth);
                    hidHaveData.Value = "0";
                }
                hidYear.Value = _a.FYear.ToString();
                hidMonth.Value = _a.FMonth.ToString();
                if (_a.Verify.HasValue && _a.Verify.Value == 1)
                {
                    labMsg0.Text = String.Format("{0}年{1}月的绩效工资已经进行过审核.", _a.FYear, _a.FMonth);
                    hidVidify.Value = "1";
                }
                
            }
            else
            {
                hidHaveMonth.Value = "0";
                hidVidify.Value = "0";
            }

        }

        /// <summary>
        /// 核算
        /// </summary>
        /// <returns></returns>
        [System.Web.Services.WebMethod]
        public static string Calculate(int year, int month)
        {
            string strmsg = String.Empty;
            HAmount.CalculatingInDate(year, month, SchoolMark, ref strmsg);
            return strmsg;
        }
    }
}